<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			function cal(){
				var num1 = document.getElementById("num").value;
				var span1 = document.getElementById("result");
				var result = 1;
				if(num1 == ""){
					span1.innerHTML = "不能为空";
					return;
				}
				if(isNaN(num1)){
					span1.innerHTML = "这不是一个数字";
					return;
				
				}else if(num1<0){
					span1.innerHTML = "负数没有阶乘";
					
				}else if (num1 == 0) {
					span1.innerHTML = 1;
				}else{
					for(var i = 1; i<=num1 ; i++){
						result = result * i;
					}
					span1.innerHTML = result;
				}
			}
		</script>
	</head>
	<body>
		<input type="text" id="num" />
		<input type="button" value="阶乘" onclick="cal()" />
		=
		<span id="result"></span>
	</body>
</html>
